<template>
	<view class="body">
		<xk-header title="设备列表"></xk-header>
		<view style="background-color: #FFFFFF;padding: 10rpx 30rpx;">
			<view class="search-area">
				<view class="search-input">
					<image class="search-icon" :src="(imgUrl+'/wx/search.png')"></image>
					<input @confirm="searchInfo" v-model="searchText" placeholder="设备编号/设备名称" placeholder-class="placeholder"/>
				</view>
			</view>
		</view>
		<view v-if="dataList.length > 0" class="list-info">
			<view v-for="(item,index) of dataList" :key="index" class="data-list">
				<view class="data-item" @click="selectDevice(item)">
					<view class="order-info">
						<view class="info-item"><view class="key">设备信息：</view>{{item.device_code}}-{{item.device_name}}</view>
						<view class="info-item"><view class="key">设备类型：</view>{{item.type_name}}</view>
						<!-- <view class="info-item"><view class="key">设备地址：</view>加速器五期E2地下生活水泵房</view> -->
					</view>
				</view>
			</view>
		</view>
		<view class="empty-view" v-else>
			<image class="empty-icon" :src="(imgUrl+'/wx/empty_data_icon.png')"></image>
			<view>哎呀，该界面暂无内容~</view>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				imgUrl:this.$config.BASE_imgUrl,
				searchText: '',
				startNum: 0,
				isAll: false,
				dataList: []
			}
		},
		onLoad(options){
			if(options.scanInfo){
				this.searchText = options.scanInfo;
			}
			this.getData()
		},
		methods: {
			searchInfo(){
				this.startNum = 0;
				this.isAll = false;
				this.getData()
			},
			getData(){
				if(this.isAll){
					return
				}
				let params = {
					start: this.startNum,
				}
				if(this.searchText){
					params.searchKey = this.searchText
				}
				this.$api.baseData_queryPdDeviceCardForPdDeviceRepair(params).then((res)=>{
					if(this.startNum == 0){
						this.dataList = res.deviceInfo
					}else{
						this.dataList = this.dataList.concat(res.deviceInfo)
					}
					if(res.deviceInfo.length < 20){
						this.isAll = true;
					}
					this.startNum += 20;
				})
			},
			selectDevice(item){
				uni.$emit('selectDevice', item);
				uni.navigateBack()
			}
		}
	}
</script>

<style lang="scss" scoped>
.list-info {
	margin: 0 30rpx;
	padding-bottom: 30rpx;
	.list-swiper{
		height: 1000rpx;
	}
	.data-list{
		background-color: #FFFFFF;
		border-radius: 10rpx;
		padding: 30rpx 20rpx;
		margin-top: 20rpx;
		.data-item{
			.order-info{
				.info-item{
					display: flex;
					font-size: 28rpx;
					color: #333333;
					line-height: 50rpx;
					.key{
						min-width: 150rpx;
						font-size: 28rpx;
						color: #999999;
					}
					.info-imgs{
						display: flex;
						flex-wrap: wrap;
						margin-bottom: 10rpx;
						.img-item{
							width: 120rpx;
							height: 120rpx;
							margin: 2rpx 2rpx 0 0;
						}
					}
				}
				.error{
					color: #FF3737;
				}
			}

			.target-info{
				flex: 1;
				display: flex;
				.img{
					width: 260rpx;
					height: 195rpx;
					border-radius: 10rpx;
					margin-right: 20rpx;
				}
				.top{
					.name{
						font-size: 28rpx;
						font-weight: bolder;
						color: #333333;
					}
					.desc{
						font-size: 28rpx;
						color: #999999;
						margin-top: 10rpx;
					}
				}
				.fee{
					display: flex;
					align-items: center;
					justify-content: space-between;
					margin-top: 30rpx;
					.amount{
						font-size: 36rpx;
						color: #FF3737;
					}
				}
			}
		}
	}
}
.search-area{
	background-color: #FFFFFF;
	padding: 20rpx 30rpx;
	.search-input{
		height: 80rpx;
		background: #F8F8F8;
		border-radius: 10rpx;
		display: flex;
		flex: 1;
		align-items: center;
		.search-icon{
			width: 48rpx;
			height: 48rpx;
			margin: 0 20rpx 0 30rpx;
		}
		input{
			height: 80rpx;
			font-size: 28rpx;
			flex: 1;
		}
	}
}
</style>
